import React, { useEffect, useState } from 'react';

// 时间格式化函数
function formatBTCDate(date: Date): string {
  const pad = (n: number) => n.toString().padStart(2, '0');
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
    `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
}

const CurrentTime: React.FC = () => {
  const [now, setNow] = useState(new Date());

  useEffect(() => {
    const timer = setInterval(() => setNow(new Date()), 1000);
    return () => clearInterval(timer);
  }, []);

  return (
    <span
      className="current-time"
      style={{
        fontSize: 14,
        fontWeight: 500,
        letterSpacing: 1,
        transition: 'opacity 0.5s',
        opacity: 1,
        color: '#1765ad',
        textShadow: '0 1px 2px #e6f7ff',
        fontFamily: 'Consolas, monospace',
      }}
      title="北京时间(BTC)"
    >
      {formatBTCDate(now)} (BTC)
    </span>
  );
};

export default CurrentTime; 